package xyz.whiteblue.render;

import xyz.whiteblue.core.Config;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by WhiteBlue on 15/6/14.
 */
public abstract class Render {

    protected String view;
    protected HttpServletRequest request;
    protected HttpServletResponse response;

    private static String encoding = Config.getENCODE();
    private static boolean devMode = Config.isDevMode();

    static final void init(String encoding, boolean devMode) {
        Render.encoding = encoding;
        Render.devMode = devMode;
    }

    public static final String getEncoding() {
        return encoding;
    }

    public static final boolean getDevMode() {
        return devMode;
    }

    public final Render setContext(HttpServletRequest request, HttpServletResponse response) {
        this.request = request;
        this.response = response;
        return this;
    }

    public final Render setContext(HttpServletRequest request, HttpServletResponse response, String viewPath) {
        this.request = request;
        this.response = response;
        if (view != null && !view.startsWith("/"))
            view = viewPath + view;
        return this;
    }

    public String getView() {
        return view;
    }

    public void setView(String view) {
        this.view = view;
    }

    /**
     * Render to client
     */
    public abstract void render();
}
